/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

/**
 *
 * @author Lu Xiaodi
 */
@Entity
public class Timeslot implements Serializable, Comparable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private Integer tsTime; //values from 0000 to 2359
    private Integer quotaMon;
    private Integer quotaTue;
    private Integer quotaWed;
    private Integer quotaThu;
    private Integer quotaFri;
    private Integer quotaSat;
    private Integer quotaSun;
    @ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
    private OutletSeatArea area;

    // Constructors
    public Timeslot() {
    }

    public Timeslot(Integer time, OutletSeatArea area) {
        this.tsTime = time;
        this.area = area;
        this.quotaMon = 0;
        this.quotaTue = 0;
        this.quotaWed = 0;
        this.quotaThu = 0;
        this.quotaFri = 0;
        this.quotaSat = 0;
        this.quotaSun = 0;
    }

    //getter and setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getTsTime() {
        return tsTime;
    }

    public void setTsTime(Integer tsTime) {
        this.tsTime = tsTime;
    }

    public String getTimeStr() {
        String prefix = "";
        if (this.tsTime < 10) {
            prefix = "000";
        } else if (this.tsTime < 100) {
            prefix = "00";
        } else if (this.tsTime < 1000) {
            prefix = "0";
        }
        String result = prefix + this.tsTime;
        return result;
    }

    public OutletSeatArea getArea() {
        return area;
    }

    public void setArea(OutletSeatArea area) {
        this.area = area;
    }

    public Integer getQuotaFri() {
        return quotaFri;
    }

    public void setQuotaFri(Integer quotaFri) {
        this.quotaFri = quotaFri;
    }

    public Integer getQuotaMon() {
        return quotaMon;
    }

    public void setQuotaMon(Integer quotaMon) {
        this.quotaMon = quotaMon;
    }

    public Integer getQuotaSat() {
        return quotaSat;
    }

    public void setQuotaSat(Integer quotaSat) {
        this.quotaSat = quotaSat;
    }

    public Integer getQuotaSun() {
        return quotaSun;
    }

    public void setQuotaSun(Integer quotaSun) {
        this.quotaSun = quotaSun;
    }

    public Integer getQuotaThu() {
        return quotaThu;
    }

    public void setQuotaThu(Integer quotaThur) {
        this.quotaThu = quotaThur;
    }

    public Integer getQuotaTue() {
        return quotaTue;
    }

    public void setQuotaTue(Integer quotaTue) {
        this.quotaTue = quotaTue;
    }

    public Integer getQuotaWed() {
        return quotaWed;
    }

    public void setQuotaWed(Integer quotaWed) {
        this.quotaWed = quotaWed;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Timeslot)) {
            return false;
        }
        Timeslot other = (Timeslot) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int compareTo(Object o) {
        if (!(o instanceof Timeslot)) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        else if (this.getTsTime()> ((Timeslot)o).getTsTime()){
            return 1;
        } else if (this.getTsTime()< ((Timeslot)o).getTsTime()){
            return -1;
        } else
            return 0;
    }

    @Override
    public String toString() {
        return area.getAreaName() + ", " + tsTime + "hrs:"
                + quotaMon + " " + quotaTue + " " + quotaWed + " " + quotaThu + " " + quotaFri + " "
                + quotaSat + " " + quotaSun;
    }
}